- /* snmshift.cpp by K.Tsuru */
- // function ID = 103 DRADIX, BRADIX
- /******************************************************************************
- SNumber class
- Shift non-zero part in figure[] to lower(shift<0) or upper(shift>0).
- In latter case the lower part is filled with zero.
- This is used for multiplication or division in the unit of radix.
- It is assumed that CheckArray() has been done,namely the value of aHead and aTail
- are decided.
- Return the sign.
-
- t = aTail, h = aHead, f = shift, s = figure.size()
- v[0]v[1]..v[t]....v[h]....v[s-1]
- v[0]v[1]....v[t+f]...v[h+f]...v[s-1]
- tail head
- ********************************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static const char* const fname = "ShiftArray";
-
- int SNumber::ShiftArray(int shift){
- if( !shift || !Sign(103) ) return 0;
-
- // head < 0 is possible
- long head = (long)aHead + shift, tail = (long)aTail + shift;
- // v[0]v[1]..v[aTail]....v[aHead]....v[s-1]
- // v[0]v[1]....v[tail]...v[head]...v[s-1]
-
- long max_sz = (long)MaxSize();
-
- if( shift < 0){//lower shift
- if( tail < 0 ){
- // SDouble/SDecimal class
- if(type & REAL) SetError(OVERFLOW_ERR, fname, 103);
- tail = 0;
- }
- if( head < 0 ){ // tail <= head < 0
- SetZero(); return 0;
- }
- } else { // shift > 0
- uint h = (uint)head;
- if( head >= max_sz ){
- if(type & DEC_INT) SetError(OVERFLOW_ERR, fname, 103);
- //SDouble|SDecimal type : It assures head < figure.size().
- if(tail >= max_sz) {
- SetZero(); return 0;
- }
- h = (uint)max_sz-1;
- }
- // aHead
- // 0.aaaa bbbb cccc .... pppp qqqq --> 0.aaaa bbbb cccc .... pppp 0000
- // --> 0.0000 aaaa cccc .... pppp
- //allocate memory, size>=h+1
- if( Reserve(h) == 0 ) SetError(FATAL, fname, 103);
- }
-
- FigBlockShift(figure, shift);
-
- if( (type & REAL) && (head >= max_sz) ){
- figure.clear((uint)max_sz); //clear outside of range
- head = max_sz-1;
- }
- //get figure positions
- //Take notice that "tail" has small value and the intermediate region is filled with zero.
- //aaaa bbbb 0000 .... 0000 dddd --> aaaa bbbb 0000 .... 0000
- if(shift < 0) while( !figure( (uint)tail ) && (tail < head) ) tail++;
- while( !figure((uint)head) && (head > 0) ) head--;
- aHead = (uint)head; aTail = (uint)tail;
- //Clearing outside of range all figures become zero.
- if( (type & REAL) && !aHead && !figure(aHead) ) SetZero();
-
- return sign;
- }
snmshift.cpp : last modifiled at 2017/03/17 11:10:49(2,474 bytes)
created at 2016/04/11 11:36:47
The creation time of this html file is 2017/10/27 10:59:17 (Fri Oct 27 10:59:17 2017).